{extend name="platform/base" /}
{block name="resources"/}
<script src="ADMIN_JS/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.config.common.js"></script>
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.all.common.js"></script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/zh-cn.js"></script>
<style>

</style>
{/block}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 伪静态路由规则： </header>
	<div class="panel-body">
		<div class="form-horizontal">
			<div class="form-group">
				<label class="col-sm-2 control-label">伪静态路由规则：</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="rule" onpaste="return false" onchange="url_route_if_exists('rule',this);" value="{$routeDetail.rule}" onKeyUp="value=value.replace(/[^\d|\w]/g,'')" maxlength="100" >
					<p class="hint"></p>
					<p class="error rule_error">该路由规则已经存在</p>
				</div>
			</div>
			
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">路由地址：</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="route" onchange="url_route_if_exists('route',this);" value="{$routeDetail.route}"  maxlength="150">
					<p class="hint">路由地址由<i style="color:#FF6600;">模块名/控制器名/方法名</i>组成，如shop/goods/goodslist</p>
					<p class="error route_error">该路由地址已经存在</p>
				</div>
			</div>
			
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">所属模块：</label>
				<div class="col-md-4">
					<select id="route_model" class="form-control" style="width:200px">
						<option value="1" {if condition="$routeDetail['route_model'] eq 1"}selected{/if}>shop</option>
					</select>
				</div>
			</div>
			
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">是否启用：</label>
				<div class="col-md-4">
					  <label for="navigationtype1" class="radio-label"><input type="radio" value="1" name="navigationtype" id="is_head" {if condition="$routeDetail['route_model'] eq 1"}checked{/if}/>开启</label>
				      <label for="navigationtype2" class="radio-label"><input type="radio" value="0" name="navigationtype" id="is_head" {if condition="$routeDetail['route_model'] eq 0"}checked{/if}/>关闭</label>
		 	     	  <p class="error">请选择</p>
		 	     </div>
			</div>
			
            <div class="line line-dashed line-lg pull-in"></div>
            <div class="form-group">
                <label class="col-lg-2 control-label">描述</label>
                <div class="col-sm-4">
                    <textarea name="store_zy"  rows="5" cols="65" id="remark" class="textarea-common">{$routeDetail['remark']}</textarea>
                	<p class="error">请输入专题描述</p>
                </div>
            </div>
            
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<a href="javascript:void(0);" onclick="save()" class="btn btn-primary">保存</a>
					<button class="btn btn-primary" style="background-color:#FF6600; border-color:#FF6600 !important" onclick="javascript:history.back(-1);" >返回</button>
				</div>
			</div>
		</div>
	</div>
</section>
{/block}
{block name="script"}
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/kindeditor/kindeditor-min.js" charset="utf-8"></script>
<script src="__STATIC__/kindeditor/lang/zh_cn.js" charset="utf-8"></script>
<script type="text/javascript">

//关键字
var keyword = new Array("addons","base","cms","components","helpcenter","login","member","notice","order","topic","basecontroller");
$(function(){
	keywordstr = keyword.join(",");
	$("#rule").next().html('伪静态路由规则不可使用<i class="important-note">"' + keywordstr +'"</i>这些关键字');
})
var rule_if_exists = false; //伪静态路由规则是否存在
var route_if_exists = false; //路由地址是否存在
//判断路由规则或者路由地址是否存在
function url_route_if_exists(type, event){
	var value = $(event).val().toLowerCase();
	$(event).val(value);
	$.ajax({
		type : "post",
		url : "{:__URL('PLATFORM_MAIN/config/url_route_if_exists')}",
		async : false,
		data : {
			"type" : type,
			"value" : value
		},
		success : function(data){
			if(data == true && type == "rule"){
				rule_if_exists = true;
				$(".rule_error").text("该路由规则已经存在").show();
			}else if(data == false && type == "rule"){
				$(".rule_error").hide();
				rule_if_exists = false;
			}
			if(data == true && type == "route"){
				route_if_exists = true;
				$(".route_error").text("该路由地址已经存在").show();
			}else if(data == false && type == "route"){
				$(".route_error").hide();
				route_if_exists = false;
			}
		}
	})
}
var is_sub = false;
function save(){
	var rule = $("#rule").val().toLowerCase();
	var route = $("#route").val().toLowerCase();
	var route_model = $("#route_model").val();
	if($("#is_head").is(":checked")){
		var is_open = 1;
	}else{
		var is_open = 0;
	}
	var remark = $("#remark").val();

	if(vertify(rule,route)){
		if(!is_sub){
			is_sub = true;
			$.ajax({
				type : "post",
				url : "{:__URL('PLATFORM_MAIN/config/updateRoutingRule')}",
				data : {
					"routeid" : {$routeid},
					"rule" : rule,
					"route" : route,
					"route_model" : route_model,
					"is_open" : is_open,
					"remark" : remark
				},
				success : function(data){
					is_sub = false;
					if(data["code"] > 0){
						showTip("修改成功","success");
						location.href = "{:__URL('PLATFORM_MAIN/config/customPseudoStaticRule')}";
					}else{
						showTip("修改失败","error");
					}
				}
			})
		}
	}
}

function vertify(rule,route){
	if(rule.length == 0){
		$(".rule_error").text("伪静态路由规则不可为空").show();
		$("#rule").focus();
		return false;
	}else if(rule_if_exists){
		$(".rule_error").text("该路由规则已经存在").show();
		$("#rule").focus();
		return false;
	}else{
		for(var i = 0; i < keyword.length; i++){
			if(rule == keyword[i]){
				$(".rule_error").text("关键字"+ keyword[i]+"不可作为路由规则").show();
				$("#rule").focus();
				return false;
			}
		}
	}
	if(route.length == 0){
		$(".route_error").text("路由地址不可为空").show();
		$("#route").focus();
		return false;
	}else if(route_if_exists){
		$(".route_error").text("该路由地址已经存在").show();
		$("#route").focus();
		return false;
	}
	$(".rule_error").hide();
	$(".route_error").hide();
	return true;
}
</script>
{/block}

